package org.xs.big_event.dao.aeticle;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ArticleReponsitory extends JpaRepository<Article, Integer> {

    /**
     * 查询用户创建的文章列表(分页查询)
     */
    @Query("SELECT a FROM Article a WHERE a.create_user = :userId " +
            "AND (:categoryId IS NULL OR a.category_id = :categoryId) " +
            "AND (:state IS NULL OR a.state = :state)")
    Page<Article> findListByUser(
            @Param("userId") Integer userId,
            @Param("categoryId") Integer categoryId,
            @Param("state") String state,
            Pageable pageable
    );
}

